package com.nabisoft.tutorials.mavenstruts.struts2.action;

import java.util.Date;

import javax.naming.InitialContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import org.apache.log4j.Logger;

public class MessageAction extends ActionSupport {
    
    private static final Logger LOGGER = Logger.getLogger(MessageAction.class);

    private String message;
    private Date nowDate;
    

    @Override
    public void validate(){
        LOGGER.debug("validate()...");
        if (message==null || message.length()==0){
            addActionError(getText("error.enter.message"));
            LOGGER.debug("vaidate(): vaidation failed because passed message is null/empty");
        }
    }

    @Override
    public String execute() throws Exception {
//        LOGGER.debug("execute()...");
//        
//        this.nowDate = new Date();
//        
//        //JNDI lookup of our EJB
//        msgService = (MessageServiceBean)new InitialContext().lookup("java:global/struts2-module-ear/struts2-module-ejb/MessageServiceBean");
//        
//        Message msg = new Message();
//        msg.setCreatedOn(this.nowDate);
//        msg.setMessage(this.message);
//        
//        msgService.save(msg);
//
//        if (msg.getId() == null){
//        	String errorMessage = getText("action.err.persist.message");
//            addActionError(errorMessage);
//            LOGGER.error(errorMessage+" (message was ==> "+this.message+")");
//        	return ERROR;
//        } 
        return SUCCESS;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Date getNowDate() {
        return nowDate;
    }
    
  
}